// Header of commonly used utility functions
//
// Copyright (C) Robert Bosch GmbH
// Date: Jan 2008
// Author: CR/RTC2-AP Kui Xu
#ifndef _IM_COMMON_UTIL_H
#define _IM_COMMON_UTIL_H

#include <string>
#include <vector>

const std::string SPACES = " \t\n\r";

void removeSpace(const char *str, char *des_str);
void removeSpaceFrom(const char *str, char *des_str, int from);

///
/// Removes all space characters from given string.
/// Characters to be removed are defined in SPACES constant
/// @param str String to process
///
void removeSpace(std::string& str);

///
/// Removes leading and traing space characters from given string.
/// Characters to be removed are defined in SPACES constant
/// @param str String to process
///
void trim(std::string& str);

///
/// Removes leading and traing space characters of all string in given vector.
/// Characters to be removed are defined in SPACES constant
/// @param list vector of strings to process
///
void trimAll(std::vector<std::string>& list);

///
/// Tests whether a string starts with another
/// @param str string to test
/// @param prefix start string to test for
/// @return true, if <code>str</code> starts with <code>prefix</code>
///
bool startsWith(const std::string& str, const std::string& prefix);

///
/// Tests whether a string ends with another
/// @param str string to test
/// @param suffix end string to test for
/// @return true, if <code>str</code> ends with <code>suffix</code>
///
bool endsWith(const std::string& str, const std::string& suffix);

void splitString(std::string *str, 
				 const char *spliter, 
				 std::vector<std::string> *result);
//void splitString(const std::string &strSrc, 
//				 const std::string &strSpliter, 
//				 std::vector<std::string> &result);
void splitString(const std::string &strSrc, 
				 const std::string &strSpliter, 
				 std::vector<std::string> &result,
				 unsigned int limit = -1);
void splitString(std::string *str, 
				 const char *spliter, 
				 std::vector<std::vector<std::string> > *result);
//const wchar_t** splitString(wchar_t *str, const wchar_t *spliter, int &count);
const wchar_t** splitString(std::string *str, const char *spliter, int &count);

const wchar_t** vectorToArray(std::vector<std::string> *vec);
bool replaceParameter(std::string &strSentence, const std::string &strParam, const std::string &strValue);
unsigned long str2Long(const char *str);
bool equalsIgnoreCase(std::string str1, std::string str2);
std::string toStr(int val);
std::string toStr(unsigned int val);
std::string toStr(double val);
std::string toStr(float val);
std::string lowercase(std::string str);
std::string uppercase(std::string str);

std::string replaceStr(std::string str, std::string subStr, std::string repStr);
std::string replaceAll(std::string str, std::string subStr, std::string repStr);

std::string joinString(std::vector<std::string> *str);
std::string joinString(std::vector<std::string> *str, int start, int number);
int getSubstrCount(std::string str, std::string subStr);

void getLocalIPAddress(std::vector<std::string> &ipAddrs);

#endif
